# # @Time    :2025/3/30 21:57
#
# # """
# # 如何动态地给类添加类方法（classmethod）和静态方法（staticmethod）
# """


class Person:
    home = "er"

    def __init__(self, name=None):
        self.name = name


@classmethod
def home(cls):
    print(f"来自{cls.home}")


# 定义静态方法
@staticmethod
def static_fun():
    print("static_fun")


# 把 home 函数赋值给 Person.home,覆盖了原来的类属性 home = "er"
Person.home = home  # 动态的  给类添加添加 类方法
Person.home()

# 直接把 static_fun方法 赋值给 Person.st_fun。
Person.st_fun = static_fun  # 动态的  给类添加添加 静态方法
Person.st_fun()




# class Person:
#     home = "earth"
#
#     def __init__(self, name=None):
#         self.name = name
#
# # 定义类方法
# @classmethod
# def come_from(cls):
#     print(f"来自{cls.home}")
#
# # 定义静态方法
# @staticmethod
# def static_function():
#     print("static function")
#
# Person.come_from = come_from
# Person.come_from()  # 来自earth
#
# Person.static_function = static_function
# Person.static_function()
